
faApp.controller('BidProductListCtrl',['$scope','bidProductService','$location','$controller','$route','$routeParams','sessionService',function($scope,bidProductService,$location,$controller,$route,$routeParams,sessionService) {

 $controller('BaseListCtrl', {$scope: $scope}); 
  $scope.showEstablishaFormFlag=false;
  $scope.showPublishFailFormFlag=false;
  $scope.config={
    "pType":"",
    "pageSize" : 20,
    "pageNo" : 1
  };
  $scope.config['orderBy'] = $routeParams.orderBy || '',
  $scope.config['orderByTag'] = $routeParams.orderByTag || '',
  $scope.orderbyPositionMap = {};
  if (!$routeParams.orderBy && !$routeParams.orderByTag){
    $scope.orderbyPositionMap['weight'] = "0";
  }else{
    $scope.orderbyPositionMap[$routeParams.orderBy] = "0";
  }
  //排序
  $scope.orderbyFreqMap = {
    "createDate":["desc","asc"]
  };


  $scope.param={
    "pType":"",
    "id":"",
    "biddingStatus":"2",
    "failReson":"",
  };
  $scope.showResonFlag=false;
  $scope.searchMap = {};
  $scope.config.pType = $routeParams.t;
  $scope.searchMap.pType = $routeParams.t;
  $scope.param.pType = $routeParams.t;

  $scope.$watch('config',function(){

    bidProductService.bidProductList($scope.config).then(function(json){
      $scope.list = json.fpBiddingReceiptList;
      $scope.pager=json.pager;
    });
  },true);

  $scope.showFailResonInput=true;
  $scope.passUpdate =function(v){
  
    if(v=='2'){
      $scope.showFailResonInput=true;
    }else{
      $scope.showFailResonInput=false;
    }
  }

  $scope.orderby = function(field){
   
    var freq = $scope.orderbyFreqMap[field];
    var old = $scope.orderbyPositionMap[field];
    $scope.orderbyPositionMap = {};
  
    if (old == undefined){
      $scope.orderbyPositionMap[field] = 0;
    }else{
      $scope.orderbyPositionMap[field] = old + 1;
      if ($scope.orderbyPositionMap[field] >= freq.length){
        $scope.orderbyPositionMap[field] = 0;
      }
    }
    if (field == "weight"){
      $scope.config.orderBy = "";
      $scope.config.orderByTag = "";
    }else{
      $scope.config.orderBy = field;
      $scope.config.orderByTag = freq[$scope.orderbyPositionMap[field]];
    }
  }
  $scope.showHide = function(id,who) {
    $scope.param.id = id;
    if(who == 1) {
      $scope.showEstablishaFormFlag = true;
    }else{
      $scope.showPublishFailFormFlag = true;     
    }
  }

  $scope.changeStatus = function(status) {
    var addAnwer = false;
    if(status == '2' || status=='6'){
      addAnwer = true;
    }
    if (addAnwer && !$scope.param.failReson) {
      alert("请填写原因");
      return;
    } else {
      $scope.param.biddingStatus = status;
      bidProductService.bidProductStatus($scope.param).then(function(json) {
        if(json.statusCode == '4010') {
          alert('没有缴保证金');
        }else if(json.statusCode == '4011'){
          alert('产品收益区间无');
        }else{
          alert('更改成功');
          addAnwer = false;
          $route.reload();
        }
      })
    }
  }
  $scope.search = function(){
    console.log($scope.searchMap);
    angular.forEach($scope.searchMap, function(o, i) {
      // console.log(i);
      $scope.config[i] = $scope.searchMap[i] || "";
      console.log($scope.config);
    });
  };
  $scope.chkProjectAll = function(){
    if($("#chkProjectAll").attr("checked") == "checked"){
      $("[name='chkProject']").attr("checked","checked");
    }else{
      $("[name='chkProject']").attr("checked",false);
    }
  }
}]);

faApp.controller('BidProductDetailCtrl',['$scope','bidProductService','$location','$controller','$route','$routeParams',function($scope,bidProductService,$location,$controller,$route,$routeParams) {
    $scope.id = $routeParams.id;
    $scope.t = $routeParams.t;//设置产品类型
    bidProductService.bidProductDetail($scope.id).then(function(json){
      $scope.detail = json.fpBiddingReceiptDetail;
    });
}]);